//
// @Author : dongshan <dongshan_li@foxmail.com>
// @copyright Copyright (c) 2020-2022 Aibots Inc.
// @version 0.1
// @date 2022-03-18 02:59:08
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//      * Redistributions of source code must retain the above copyright
//        notice, this list of conditions and the following disclaimer.
//      * Redistributions in binary form must reproduce the above copyright
//        notice, this list of conditions and the following disclaimer in the
//        documentation and/or other materials provided with the distribution.
//      * Neither the name of Aibots, Inc. nor the
//        names of its contributors may be used to endorse or promote products
//        derived from this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL Aibots, INC. BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 
// Please send comments, questions, or patches to dongshan_li@foxmail.com
// 

#include "observation_buffer.h"

namespace tf2_test {

ObservationBuffer::ObservationBuffer(tf2_ros::Buffer& tf2_buffer, std::string global_frame, double tf_tolerance) :
    tf2_buffer_(tf2_buffer),
    global_frame_(global_frame),
    tf_tolerance_(tf_tolerance) {

}

ObservationBuffer::~ObservationBuffer() {

}

bool ObservationBuffer::setGlobalFrame(const std::string new_global_frame) {
    ros::Time transform_time = ros::Time::now();
    std::string tf_error;

    geometry_msgs::TransformStamped transformStamped;
    if (!tf2_buffer_.canTransform(new_global_frame, global_frame_, transform_time, ros::Duration(tf_tolerance_), &tf_error)) {
        ROS_INFO_STREAM(tf_error); 
        return false;
    }
    return true;
}

}   // namespace tf2_test